<?php

namespace App\Console\Commands;

use App\Facades\CollectionRequestFacade;
use App\Models\Collection\RepayRecord;
use App\Models\Collection\RepaySummary;
use App\Models\Collection\UserInfo;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Models\Traits\RepayInfo;
use App\Models\UserLoanRequest;
use App\Models\UserAuthSpiderTransLog;
use Illuminate\Support\Facades\Log;
use Illuminate\Database\Eloquent\Collection;
use App\Library\ArrayTools\ArrayTools;
use App\Models\Collection\UserBankCard;


class RepaymentCommand extends Command
{
    use RepayInfo;
    use \App\Models\Traits\RepaySummary;
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'repayment:cron {action : news|propelNews} {--tn=} {--not=}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'repayment cron relevant';

    /**
     * The console command action. month|common|money|help
     *
     * @var string
     */
    protected $action;

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $this->initAction();
        $this->runAction();
    }

    /**
     * Description: 推送t-3数据
     * Author: Gxs
     */
    public function propelNews()
    {
        $this->info('start');
        $t0 = microtime(true);
        $tn = $this->option('tn'); //获取options 查询t-n
        $not_repay = $this->option('not'); //获取options 查询未还清
        $current_date = Carbon::now()->format('Y-m-d');

            //逾期的测试条件
//            $test_summary_ids = RepayRecord::where('normal_date', '<', '2019-03-30')
//                ->select('summary_id')
//                ->groupBy('summary_id')
//                ->pluck('summary_id');

        RepaySummary::when($tn, function ($query) use ($tn) {
            $n_days = Carbon::parse('+' . $tn . ' day')->toDateString();
            $query->leftJoin('repay_records as a', 'a.summary_id', '=', 'repay_summaries.id');
            $query->where('a.period', 1);
            $query->where('a.normal_date', $n_days);
        })
            ->when($not_repay, function ($query) {
                $query->where('status', RepaySummary::STATUS_ONE);
            })
//                ->whereIn('repay_summaries.id', $test_summary_ids) //逾期测试条件
        //        ->where('repay_summaries.id', 24) //测试条件
            ->select(['repay_summaries.id', 'repay_summaries.uid'])
            ->chunk(20, function (Collection $summary_collection) use ($t0, $current_date) {
                $summary_ids = $summary_collection->pluck('id');
                $uids = $summary_collection->pluck('uid');
                try {
                    //获取这一批所有的银行卡
                    $user_bank_cards = UserBankCard::whereIn('uid', $uids)
                        ->select(['uid', 'card_num', 'bank_name', 'phone_num'])
                        ->get();
                    $user_bank_cards_exchange = ArrayTools::valuesToKey($user_bank_cards->toArray(), 'uid');
                    //获取这一批用户的基础信息
                    $user_infos = UserInfo::whereIn('user_id', $uids)
                        ->select([
                            'user_id',
                            'company',
                            'work_phone',
                            'linkman_first',
                            'linkman_first_relation',
                            'linkman_first_phone',
                            'linkman_second',
                            'linkman_second_relation',
                            'linkman_second_phone',
                            'phone_address_list'
                        ])
                        ->groupBy('user_id')
                        ->get();
                    $user_infos_exchange = ArrayTools::valueToKey($user_infos->toArray(), 'user_id');
                    $summaries = RepaySummary::leftJoin('repay_records as a', 'a.summary_id', '=', 'repay_summaries.id')
                        ->leftJoin('repay_record_months as b', 'a.id', '=', 'b.record_id')
                        ->leftJoin('repay_record_moneys as c', 'a.id', '=', 'c.record_id')
                        ->leftJoin('repay_record_commons as d', 'a.id', '=', 'd.record_id')
                        ->leftJoin('loan_apply as e', 'repay_summaries.loan_request_id', '=', 'e.loan_request_id')
                        ->leftJoin('user_loan_requests as f', 'repay_summaries.loan_request_id', '=', 'f.id')
                        ->leftJoin('users as g', 'repay_summaries.uid', '=', 'g.id')
                        ->leftJoin('user_cert_ocrs as h', function ($join) {
                            $join->on('repay_summaries.uid', '=', 'h.user_id')
                                ->where('h.is_valid', 1)
                                ->where('h.id_card_front', '<>', '')
                                ->where('h.id_card_back', '<>', '');
                        })
                        ->whereIn('repay_summaries.id', $summary_ids)
                        ->where('a.period', '>', 0)
//                    ->where('repay_summaries.id', 43781)
                        ->select([
                            'repay_summaries.loan_request_id',
                            'repay_summaries.id as summary_id',
                            'repay_summaries.loan_id as case_code',
                            'repay_summaries.uid',
                            'repay_summaries.period',
                            'repay_summaries.period_count',
                            'repay_summaries.amount as summary_amount',
                            'repay_summaries.rate',
                            'repay_summaries.data_type',
                            'repay_summaries.trans_id',
                            'repay_summaries.loan_id',
                            'repay_summaries.loan_request_id',
                            'repay_summaries.repay_type as summary_repay_type',
                            //a 是repay_records
                            'a.id as record_id',
                            'a.amount as record_amount',
                            'a.period as record_period',
                            'a.status as record_status',
                            'a.normal_date',
                            'a.pay_off as pay_off',
                            'a.repay_plan_number as repay_plan_number',
                            'a.created_at as record_create_at',
                            'a.repay_date as repay_date',
                            'a.pay_off as repay_pay_off',
                            //b 是repay_record_months
                            'b.amount as month_amount',
                            'b.status as month_status',
                            //c 是repay_record_moneys
                            'c.fines_money as money_fines',
                            'c.lending_money as money_lending',
                            'c.manage_money as money_manage',
                            'c.relief_amount as relief_amount',
                            'c.status as money_status',
                            //d 是repay_record_commons
                            'd.fines_money as common_fines',
                            'd.lending_money as common_lending', //兼容老数据
                            'd.manage_money as common_manage',
                            'd.status as common_status',
                            //e 是loan_apply
                            'e.loan_time as apply_loan_time',
                            'e.pre_insurance_amt',
                            'e.performance_insurance',
                            //f 是user_loan_requests
                            'f.channel as requests_channel',
                            //g users
                            'g.marry_status',
                            'g.phone_num',
                            //h 是user_cert_ocrs
                            'h.name as ocrs_name',
                            'h.num as ocrs_num',
                            'h.domicile_address',
                            'h.id_card_front',
                            'h.id_card_back',
                            'h.hand_cert',
                            'h.old_kskd_user_id as ocrs_old_kskd_user_id',
                        ])
                        ->groupBy('record_id')
                        ->orderBy('repay_summaries.id', 'asc')
//                    ->toSql();
                        ->get();
//                print_r($summaries);exit;
                    //响应结果数组
                    $req_data = [];
                    $summaries_exchange = ArrayTools::valuesToKey($summaries->toArray(), 'summary_id');
//                print_r($summaries_exchange);exit;
                    foreach ($summaries_exchange as $key => $records) {
                        if (empty($records))
                            continue;
                        $temp_period_overdue = []; //当前逾期期数
                        $temp_success_period = 0; //已还期数
                        $temp_overdue_days = 0; //逾期天数
                        $temp_fines = 0; //未还罚息
                        $temp_amount = 0; //未还剩余本金
                        $temp_lending = 0; //未还剩余利息
                        $temp_manage = 0; //未还剩余贷后管理费
                        $temp_repayment_money_current = 0; //当前已还总额
                        $temp_not_repayment_money_current = 0; //当前未还总额
                        $temp_not_normal_money = 0; //当前未到还款日总额
                        $temp_overdue_time = ''; //最早逾期的起始日
                        $relief_amount = ''; //减免金额
                        $repayPlanList = []; //还款计划表

                        array_walk($records, function (&$item) use (
                            $t0,
                            &$temp_period_overdue,
                            &$temp_success_period,
                            &$temp_overdue_days,
                            &$temp_fines,
                            &$temp_amount,
                            &$temp_lending,
                            &$temp_manage,
                            &$temp_repayment_money_current,
                            &$temp_not_repayment_money_current,
                            &$temp_not_normal_money,
                            &$temp_overdue_time,
                            &$relief_amount,
                            &$repayPlanList,
                            $current_date
                        ) {
                            $current_not_repayment_money = 0;
                            $current_not_normal_money = 0;
                            $item['collection_status'] = RepayRecord::COLLECTION_STATUS_THREE;
                            if ($item['record_status'] == RepayRecord::STATUS_ONE
                                || $item['record_status'] == RepayRecord::STATUS_THREE
                            ) {
                                //待处理 || 失败的记录
                                $item['collection_status'] = RepayRecord::COLLECTION_STATUS_THREE;
                                //当前期的未还金额
                                $current_not_repayment_money = RepayRecord::getNotRepaymentMoneyCurrent($item);
                                $temp_not_repayment_money_current += $current_not_repayment_money;
                                //未还利息和 = 提前结清手续费
                                $temp_lending += bcadd($item['money_lending'], $item['common_lending'], 2);
                                $temp_manage += bcadd($item['money_manage'], $item['common_manage'], 2);
                                //未还本金
                                $temp_amount += $item['record_amount'];
                            }
                            if (($item['record_status'] == RepayRecord::STATUS_ONE
                                    || $item['record_status'] == RepayRecord::STATUS_THREE)
                                && $item['normal_date'] > $current_date
                            ) {
                                //待处理 || 失败的记录 && 未到还款日(包含还款日)
                                $current_not_normal_money = RepayRecord::getNotRepaymentMoneyCurrent($item);
                                $temp_not_normal_money += $current_not_normal_money;
                            }
                            if (($item['record_status'] == RepayRecord::STATUS_ONE
                                    || $item['record_status'] == RepayRecord::STATUS_THREE)
                                && $item['normal_date'] < $current_date
                            ) {
                                //待处理 || 失败的记录 && 逾期
                                $item['collection_status'] = RepayRecord::COLLECTION_STATUS_TWO;
                                $temp_period_overdue[] = $item['record_period'];
                                //单个最长逾期天数
                                if (0 == $temp_overdue_days)
                                    $temp_overdue_days = Carbon::parse($item['normal_date'])->diffInDays($current_date, false);
                                //计算未还罚息
                                $temp_fines += bcadd($item['money_fines'], $item['common_fines'], 2);
                                if (empty($temp_overdue_time))
                                    $temp_overdue_time = Carbon::parse($item['normal_date'])->addDays(1)->timestamp;
                            }
                            if ($item['record_status'] == RepayRecord::STATUS_FOUR) {
                                //成功的记录
                                $item['collection_status'] = RepayRecord::COLLECTION_STATUS_ONE;
                                ++$temp_success_period;
                                //当前期已还总额
                                $current_repayment_money = RepayRecord::getRepaymentMoneyCurrent($item);
                                $temp_repayment_money_current += $current_repayment_money;
                            }
                            //还款计划表
                            $result = RepayRecord::getRepaymentPlan($item);
                            $result['debtMoney'] = bcsub($current_not_repayment_money, $current_not_normal_money, 2);
                            $repayPlanList[] = $result;
                        });

                        /**
                         * 案件信息
                         */
                        // 结款号
                        $case_msg['caseCode'] = $records[0]['case_code'];
                        //产品名称
                        $case_msg['productName'] = '快闪卡贷';
//                    switch ($records[0]['summary_repay_type']) {
//                        case RepaySummary::KSKD_REPAY_TYPE_ZERO:
//                            $case_msg['productName'] = '快闪卡贷2';
//                            break;
//                        case RepaySummary::KSKD_REPAY_TYPE_ONE;
//                            $case_msg['productName'] = '快闪卡贷';
//                            break;
//                        case RepaySummary::KSKD_REPAY_TYPE_TWO:
//                            $case_msg['productName'] = '快闪卡贷1';
//                            break;
//                        case RepaySummary::KSKD_REPAY_TYPE_THREE;
//                            $case_msg['productName'] = '快闪卡贷';
//                            break;
//                    }
                        //贷款金额
                        $case_msg['borrowMoney'] = bcdiv($records[0]['summary_amount'], 100, 2);
                        //放款⽇期（时间戳，毫秒）
                        $case_msg['borrowTime'] = empty($records[0]['apply_loan_time']) ? '' : Carbon::parse($records[0]['apply_loan_time'])->timestamp * 1000;
                        //保费(前置险+履约险)
                        $case_msg['guaranteeCost'] = bcdiv(bcadd($records[0]['pre_insurance_amt'], $records[0]['performance_insurance'], 2), 100, 2);
                        //账单⽇
                        $case_msg['billDay'] = empty($records[0]['apply_loan_time']) ? '' : Carbon::parse($records[0]['apply_loan_time'])->format('d');
                        //每期贷后管理费（每期服务费）
                        $case_msg['periodServiceFee'] = bcdiv(bcadd($records[0]['money_manage'], $records[0]['common_manage'], 2), 100, 2);
                        //每期本金
                        $case_msg['principalPeriod'] = bcdiv($records[0]['record_amount'], 100, 2);
                        //每期利息
                        $case_msg['interestPeriod'] = bcdiv(bcadd($records[0]['money_lending'], $records[0]['common_lending'], 2), 100, 2);
                        //资方
                        switch ($records[0]['requests_channel']) {
                            case '10009':
                                $channel_name = '光大';
                                break;
                            case 'JCFC':
                                $channel_name = '晋商';
                                break;
                            case 'long_xin':
                                $channel_name = '龙信';
                                break;
                            default:
                                $channel_name = '未知';
                                break;
                        }
                        $case_msg['moneySource'] = $channel_name;
                        //总期数
                        $case_msg['periodTotal'] = $records[0]['period_count'];
                        //当前逾期期数
                        $case_msg['periodOverdue'] = implode(',', $temp_period_overdue);
                        //已还期数
                        $case_msg['periodRepay'] = $temp_success_period;
                        //逾期天数（单个最长逾期时间）
                        $case_msg['overdueDay'] = $temp_overdue_days;
                        //未还罚息
                        $punish_interest_total = bcdiv($temp_fines, 100, 2);
                        $case_msg['punishInterestTotal'] = $punish_interest_total;
                        //未还剩余本金
                        $residual_money = bcdiv($temp_amount, 100, 2);
                        $case_msg['residualMoney'] = $residual_money;
                        //提前还清手续费 = 未还利息和
                        $repayment_money = bcdiv(bcadd($temp_lending, $temp_manage, 2), 100, 2);
                        // 结清应还（本金+手续费+罚息）
                        $case_msg['settleMoney'] = bcadd(bcadd($punish_interest_total, $residual_money, 2), $repayment_money, 2);
                        // 当前已还总额
                        $case_msg['repaymentMoneyCurrent'] = $temp_repayment_money_current;
                        // 逾期总额
                        $debt_money = bcsub($temp_not_repayment_money_current, $temp_not_normal_money, 2);
                        $case_msg['debtMoney'] = $debt_money;
                        // 逾期起始日
                        $case_msg['overdueTime'] = empty($temp_overdue_time) ? '' : $temp_overdue_time * 1000;//转成时间戳（毫秒）
//                        Log::debug('collection_update_command', ['case_msg'=> $case_msg, 'repay_plan_list' => $repayPlanList]);
                        /**
                         * 用户信息
                         */
                        //债务⼈姓名
                        $borrower_msg['borrowerName'] = $records[0]['ocrs_name'];
                        //婚姻状态
                        $borrower_msg['borrowerMarriage'] = $records[0]['marry_status'] == 1 ? '已婚' : '未婚';
                        //债务⼈联系电话
                        $borrower_msg['borrowerTel'] = $records[0]['phone_num'];
                        //债务⼈证件类型（0：表示身份证）
                        $borrower_msg['borrowerCardType'] = 0;
                        //债务⼈证件号码
                        $borrower_msg['borrowerIdcard'] = $records[0]['ocrs_num'];
                        //性别 1男2女
                        $sex = 1;
                        if (!empty($records[0]['ocrs_num']))
                            $sex = substr($records[0]['ocrs_num'], -2, 1); //0是女 1是男
                        $sex_result = $sex % 2;
                        $borrower_msg['gender'] = empty($sex_result) ? 2 : 1;
                        //债务⼈年龄 $user->age
                        $age = date('Y') - substr($records[0]['ocrs_num'], 6, 4);
                        $borrower_msg['age'] = $age;
                        //债务⼈教育程度
                        $borrower_msg['education'] = '';
                        //有⽆⼦⼥( 0 : ⽆ 1: 有)
                        $borrower_msg['haveChildren'] = '';
                        //户籍地
                        $borrower_msg['registeredResidence'] = $records[0]['domicile_address'];
                        //现居地
                        $borrower_msg['residenceAddress'] = $records[0]['domicile_address'];
                        //单位名称
                        $borrower_msg['workCompany'] = '';
                        //单位电话
                        $borrower_msg['workTel'] = '';
                        //单位地址
                        $borrower_msg['addrWork'] = '';
                        //部门名称
                        $borrower_msg['departmentName'] = '';
                        //职位名称
                        $borrower_msg['positionName'] = '';
                        //qq帐号
                        $borrower_msg['qqAccount'] = '';
                        //微信账号
                        $borrower_msg['wechatAccount'] = '';
                        //电⼦邮箱
                        $borrower_msg['email'] = '';
                        //个⼈⼿持身份证照⽚url
                        $borrower_msg['idcardHold'] = $records[0]['hand_cert'];
                        //身份证正⾯url
                        $borrower_msg['idcardFront'] = $records[0]['id_card_front'];
                        //身份证反⾯url
                        $borrower_msg['idcardBack'] = $records[0]['id_card_back'];
                        //征信信息
                        $borrower_msg['creditInfoUrl'] = '';
                        /**
                         * 获取银行卡信息
                         */
                        $bank_card_list = [];
                        if (isset($user_bank_cards_exchange[$records[0]['uid']])) {
                            $bank_card = $user_bank_cards_exchange[$records[0]['uid']];
                            array_walk($bank_card, function ($item) use (&$bank_card_list) {
                                $temp = [
                                    'bankCard' => $item['card_num'],
                                    'bankName' => $item['bank_name'],
                                    'bindPhone' => $item['phone_num'],
                                ];
                                $bank_card_list[] = $temp;
                            });
                        }
                        /**
                         * 联系人信息
                         */
                        $contact_list = [];
                        if (!empty($user_infos_exchange) && isset($user_infos_exchange[$records[0]['uid']])) {
                            $user_info = $user_infos_exchange[$records[0]['uid']];
                            //紧急联系人信息
                            $temp1 = [
                                'contactName' => $user_info['company'],
                                'contactTel' => $user_info['work_phone'],
                                'originType' => 1, //todo const
                                'relation' => '工作单位',
                            ];
                            $temp2 = [
                                'contactName' => $user_info['linkman_first'],
                                'contactTel' => $user_info['linkman_first_phone'],
                                'originType' => 1, //todo const
                                'relation' => UserInfo::$USER_RELATION[$user_info['linkman_first_relation']],
                            ];
                            $temp3 = [
                                'contactName' => $user_info['linkman_second'],
                                'contactTel' => $user_info['linkman_second_phone'],
                                'originType' => 1, //todo const
                                'relation' => UserInfo::$USER_RELATION[$user_info['linkman_second_relation']],
                            ];
                            $contact_list[] = $temp1;
                            $contact_list[] = $temp2;
                            $contact_list[] = $temp3;
                            //通讯录
                            if (!empty($user_info['phone_address_list'])) {
                                $phone_address_list = json_decode($user_info['phone_address_list'], true);
                                if (!empty($phone_address_list)) {
                                    $temp_address_sign = [];
                                    array_walk($phone_address_list, function ($item) use (&$contact_list, &$temp_address_sign) {
                                        if (isset($item['phone']) && !in_array($item['phone'], $temp_address_sign)) {
                                            $temp_address_sign[] = $item['phone'];
                                            $temp_address_list = [
                                                'contactName' => isset($item['contactName']) ? $item['contactName'] : '联系人名字为空',
                                                'contactTel' => $item['phone'],
                                                'originType' => 2, //todo const
                                                'relation' => UserInfo::$USER_RELATION[UserInfo::RELATION_OTHER],
                                            ];
                                            $contact_list[] = $temp_address_list;
                                        }
                                    });
                                }
                            }
                        }

                        $req_data[] = [
                            'caseMsg' => $case_msg,
                            'borrowerMsg' => $borrower_msg,
                            'repayPlanList' => $repayPlanList,
                            'bankCardList' => $bank_card_list,
                            'contactList' => $contact_list,
                        ];
//                        print_r($req_data);
//                        exit;
                    }
                    $result = CollectionRequestFacade::sendNewCase($req_data);
                    Log::debug('collection_news_command', ['collection_news_command'=> $result]);
//                        $list['borrowerMsg'],
//                        $list['contactList'],
//                        $list['bankCardList'],
//                        $list['thirdPartyList']
//                    );
                    $this->info('批处理时间:' . round(microtime(true) - $t0, 2) . 's');
                } catch (\Exception $e) {
                    Log::debug('collection_news_exception', [
                        'summary_ids' => $summary_ids,
                        'file' => $e->getFile(),
                        'line' => $e->getLine(),
                        'message' => $e->getMessage(),
                    ]);
                }
            });
        $time = round(microtime(true) - $t0,2);
        $this->info('done, 执行时间' . $time . 's');
    }

    public function getInformation($item)
    {
        try{
//            $phoneDetail = \App::make(UserAuthSpiderTransLog::class)->phoneDetail(UserLoanRequest::find($val->loan_request_id));
//            $receiver = \App::make(UserAuthSpiderTransLog::class)->receiver(UserLoanRequest::find($val->loan_request_id));
            $phoneDetail = \App::make(UserAuthSpiderTransLog::class)->phoneDetail(UserLoanRequest::find($item['loan_request_id']));
            $receiver = \App::make(UserAuthSpiderTransLog::class)->receiver(UserLoanRequest::find($item['loan_request_id']));

        }catch (\Exception $e){
            $phoneDetail = [];
            $receiver   =[];

        }
        $list=[];
        $list['thirdPartyList']=[];
        $list['contactList']=[];
        $data=[];
        if ($receiver){
            foreach ($receiver as $key => $val ){
                $list['thirdPartyList'][$key]['type'] = 2; //目前只有淘宝
                $list['thirdPartyList'][$key]['receiverName'] = $val['name'];
                $list['thirdPartyList'][$key]['receiverPhone'] = $val['phone_number'];
                $list['thirdPartyList'][$key]['receiverAddress'] = $val['full_address'];
            }
        }

        if ($phoneDetail && isset($phoneDetail['dial_data'])){
            //主叫
            foreach ($phoneDetail['dial_data'] as $key => $val ){
                $data['contactList'][$key]['contactName'] = '';
                $data['contactList'][$key]['contactTel'] = $val['phone'];
                $data['contactList'][$key]['originType'] = 3;
                $data['contactList'][$key]['relation'] = '';
                $data['contactList'][$key]['telLocation'] = $phoneDetail['city'];
                $data['contactList'][$key]['callDuration'] = '';
                $data['contactList'][$key]['callType'] = 2;//呼出为2
                $data['contactList'][$key]['activeCalNo'] = $val['total'];//主叫次数
                $data['contactList'][$key]['passiveCallNo'] = 0;//被叫次数为0
                $data['contactList'][$key]['createTime'] = $phoneDetail['last_modify_time'];
                $data['contactList'][$key]['updateTime'] = '';
            }
        }

        if ($phoneDetail && isset($phoneDetail['dialed_data'])){
            //被叫
            foreach ($phoneDetail['dialed_data'] as $key => $val ){
                $data['contactLists'][$key]['contactName'] = '';
                $data['contactLists'][$key]['contactTel'] = $val['phone'];
                $data['contactLists'][$key]['originType'] = 3;
                $data['contactLists'][$key]['relation'] = '';
                $data['contactLists'][$key]['telLocation'] = $phoneDetail['city'];
                $data['contactLists'][$key]['callDuration'] = '';
                $data['contactLists'][$key]['callType'] = 1;//呼入1
                $data['contactLists'][$key]['activeCalNo'] = 0;//主叫为0
                $data['contactLists'][$key]['passiveCallNo'] = $val['total'];//被叫次数
                $data['contactLists'][$key]['createTime'] = $phoneDetail['last_modify_time'];
                $data['contactLists'][$key]['updateTime'] = '';
            }
        }
        if ($phoneDetail && isset($phoneDetail['dialed_data']) && isset($phoneDetail['dial_data'])){
            $phoneDetails=array_merge($data['contactList'],$data['contactLists']);
        }elseif (isset($phoneDetail['dialed_data'])){
            $phoneDetails = $data['contactLists'];
        }elseif(isset($phoneDetail['dial_data'])){
            $phoneDetails = $data['contactList'];
        }else{
            $phoneDetails = [];
        }
        $list['contactList'] = $phoneDetails;
        return $list;

    }

    /**
     * Description: Initialize command action.
     * Author: Gxs
     */
    protected function initAction()
    {
        $this->action = $this->argument('action');

        if (!in_array($this->action, ['news','propelNews'])) {
            $this->error("Invalid argument '{$this->action}'. Expected 'news'.");
            exit(1);
        }
    }

    /**
     * Description: Run action.
     * Author: Gxs
     */
    protected function runAction()
    {
        $this->{$this->action}();
    }
}